module.exports = {
	methods: {
		// 推送formid
		__pushFormid__: function(e) {
			if (!e.detail.formId) return;
			wx.pushFormid(e.detail.formId);
		},

		// 设置data值
		setValue: function(e) {
			if (e.detail && e.detail.formId) {
				wx.pushFormid(e.detail.formId);
			}
			this.setData(e.target.dataset);
		},

		//设置data属性
		setDataTap: function(e) {
			// JSON.parse() 将字符串数据转换成对象
			const data = JSON.parse(e.currentTarget.dataset.data || "{}"),
				originalData = this.data;

			const result = {};
			for (const key in data) {
				if (typeof originalData[key] !== "object") {
					originalData[key] = data[key];
				} else {
					if (typeof originalData[key] === "object" && typeof data[key] === "object") {
						Object.deepAssign(originalData[key], data[key]);
					} else {
						originalData[key] = data[key];
					}
				}

				result[key] = originalData[key];
			}

			this.setData(result);
		},

		// 跳转页面
		linkToTap: function(e) {
			let url = e.currentTarget.dataset.url;
			wx.navigateTo({
				url: url,
			})
		}
	}
};
